package edu.sctu.zhangwang.month201506.day20150628.test_day0628.get_json;

import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**
 * Created by Administrator on 2015/6/28.
 */
public class GetData {
    public String write(String url, String parm) {
        byte[] bytes = new byte[1024];
        int count = 0;
        String star="";
        try {
            URL url1 = new URL(url);
            try {
                URLConnection urlConnection = url1.openConnection();
                urlConnection.setDoOutput(true);
                urlConnection.connect();

                OutputStream outputStream = urlConnection.getOutputStream();
                outputStream.write(parm.getBytes());
                outputStream.close();

                InputStream input = urlConnection.getInputStream();
                while ((count = input.read(bytes)) != -1) {
                    star += new String(bytes, 0, count, "utf-8");
                }
                System.out.println(star);
                input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        return star;
    }

    public static void main(String[] args) {
        GetData getData = new GetData();
        getData.write("http://api.ii.com.cn/goods/apprec","page=1&size=10");
    }
}
